using System.ComponentModel;
using System.Xml.Serialization;

namespace Microsoft.WowAddonStudio.Lua.Model
{
    /// <summary>
    /// A lua declaration that has a logical API type on top of its Lua type.
    /// </summary>
    public class ApiDeclaration : Declaration
    {
        private ApiType apiType;

        /// <summary>
        /// Gets or sets the logical API type of the declaration.
        /// </summary>
        [XmlAttribute("apitype")]
        [DefaultValue(ApiType.Unknown)]
        public ApiType ApiType
        {
            get { return apiType; }
            set
            {
                apiType = value;

                // Set the type of the declaration based on the value type
                switch (apiType)
                {
                    case ApiType.OneNil:
                    case ApiType.Team:
                    case ApiType.BagId:
                    case ApiType.InventoryId:
                    case ApiType.ItemId:
                        this.Type = LuaType.Number;
                        break;
                    case ApiType.UnitId:
                    case ApiType.ItemString:
                    case ApiType.ItemLink:
                        this.Type = LuaType.String;
                        break;
                }
            }
        }
    }
}